﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZLCMS.Business;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business.Util;
using ZLCMS.Data.Model;
using ZLCMS.Web.SystemManage.Control;
using System.Collections.Generic;
using NHibernate;
using DotNet.Common.TransferParam;
using NHibernate.Criterion;
using DotNet.Common.NHibernateUtil;

namespace ZLCMS.Web.SystemManage.Basics.Advert
{
    public partial class AdvertAdd : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new FrameHelper(this);
            //初始化DWZ控件
            if (!IsPostBack)
            {
                ParamKit.Bind("ShopAdvertPosition", ddl_position, null, null, null, "-1", null);
                position_Code.Value = (String.IsNullOrEmpty(Request["code"]) ? "" : Request["code"]);

                ParamKit.Bind("YesNo_10", ddl_status, null, null, null, "0", null);

                ddl_position.SelectedValue = position_Code.Value;
            }
            else
            {
                AddBussines();
            }
        }

        #region 添加产品 +protected void AddBussines()
        /// <summary>
        /// 添加产品
        /// </summary>
        protected void AddBussines()
        {
            ShopAdvertInfo advertDB = new ShopAdvertInfo();
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                advertDB.Title = txt_title.Text.Trim();
                advertDB.Description = txt_des.Text;
                advertDB.PositionCode = ddl_position.SelectedValue;
                advertDB.Url = txtUrl.Text;
                advertDB.PhotoUrl = fc_relatedimgs.Value;
                advertDB.Sort = Convert.ToInt32(string.IsNullOrEmpty(txt_sort.Text.Trim()) ? "9999" : txt_sort.Text.Trim());
                advertDB.Param1 = txt_param1.Text.Trim();
                //advertDB.Param2 = txt_param2.Text.Trim();
                //advertDB.Param3 = txt_param3.Text.Trim();
                //advertDB.Param4 = txt_param4.Text.Trim();
                //advertDB.Param5 = txt_param5.Text.Trim();
                advertDB.Status = ddl_status.SelectedValue;

                session.Save(advertDB);
                session.Flush();

                _framePage.Alert(new ReturnCode()
                {
                    statusCode = 200,
                    message = "操作成功!",
                    callbackType = "closeCurrent",
                    navTabId = _framePage.NavTabId
                });
            }
        }
        #endregion

    }
}
